<extend name="Application/Admin/View/Layout/application.html" />
<block name="css">
    <link href="__PUBLIC__/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/select2/css/select2.min.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/bootstrap-colorpicker/css/bootstrap-colorpicker.min.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/bootstrap-datepicker/css/bootstrap-datepicker3.min.css">
</block>
<block name="content">


    <div class="row">
        <div class="col-md-10">
            <div class="panel panel-default">
                <div class="panel-heading">新增文章</div>

                <div class="panel-body">
                    <div class="bs-example" data-example-id="simple-horizontal-form">
                        <form class="form-horizontal" method="post" action="{{:U('store')}}">
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">所属栏目</label>
                                <div class="col-sm-6">

                                    <select class="form-control" name="category_id" >
                                        <volist name="categories" id="category">
                                            <option value="{{$category.id}}">{{$category.name}}</option>
                                            <volist name="category['children']" id="c">
                                                <option value="{{$c.id}}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{$c.name}}</option>
                                            </volist>
                                        </volist>
                                    </select>

                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">标题</label>
                                <div class="col-sm-6">
                                    <input type="text" class="form-control" name="title" id="title" placeholder="title" >
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">标题颜色</label>
                                <div id="cp2" class="input-group colorpicker-component col-sm-3">
                                    <input type="text" value="#00AABB" class="form-control " name="colour"/>
                                    <span class="input-group-addon"><i></i></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">发布时间</label>
                                <div class="col-sm-6">
                                    <input type="text" class="form-control" name="date" id="time" placeholder="">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">Description Field</label>
                                <div class="col-sm-6">
                                    <input type="text" class="form-control" name="field" id="field" placeholder="field" >
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">摘要</label>
                                <div class="col-sm-6">
                                    <textarea class="form-control" rows="5" name="zaiyao"></textarea>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">缩略图</label>
                                <div class="col-sm-10 ">
                                    <span class="col-sm-5">
                                    <input type="text" class="form-control " id="thumb1" name="thumb">
                                    </span>
                                    <input type="button"  value="上 传" onclick="BrowseServer('thumb1','img_show1')" class=" btn btn-success" />
                                    <input type="button" value="删 除" class=" thumb_del1 btn btn-danger">
                                    <img src="" class="col-sm-2"id="img_show1" width="90px" height="90px" />

                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">新增附件:</label>
                                <div class="col-sm-6">
                                    <span class="btn btn-primary add_file">增 加</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">附件列表</label>
                                    <div class="col-sm-10 file">
                                    <span class="col-sm-8">
                                        <input type="text" id="file1" class="span5" name="file[]" value="">
                                    </span>
                                        <input type="button" value="上 传" onclick="BrowseServer('file1')" class="btn btn-success">
                                        <input type="button" value="删 除" class="file_del1 btn btn-danger">

                                    </div>
                            </div>

                            <div class="form-group">
                                <div >
                                    <textarea name="category_content" class="content" id="textarea"></textarea>
                                </div>
                            </div>



                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-10">
                                    <button type="submit" class="btn btn-default">提交</button>
                                    <button type="button" class="btn btn-default">返回</button>
                                </div>
                            </div>
                        </form>
                    </div>


                </div>
            </div>
        </div>
    </div>


</block>

<block name="js">



    <script type="text/javascript" src="__PUBLIC__/select2/js/select2.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/select2/js/i18n/zh-CN.js"></script>
    <script type="text/javascript" src="__PUBLIC__/bootstrap-colorpicker/js/bootstrap-colorpicker.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
    <script src="__PUBLIC__/ckeditor/ckeditor.js"></script>
    <script src="__PUBLIC__/ckfinder/ckfinder.js"></script>

    <script type="text/javascript">
        $(function () {
            $('select').select2();
            $('#cp2').colorpicker();
            $('#time').datepicker({
                format: "yyyy-mm-dd",
                language: "zh-CN"
            });
        });
        CKEDITOR.replace('category_content',
                {
                    filebrowserBrowseUrl: '__PUBLIC__/ckfinder/ckfinder.html',
                    filebrowserImageBrowseUrl: '__PUBLIC__/ckfinder/ckfinder.html?type=Images',
                    filebrowserFlashBrowseUrl: '__PUBLIC__/ckfinder/ckfinder.html?type=Flash',
                    filebrowserUploadUrl: '__PUBLIC__/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
                    filebrowserImageUploadUrl: '__PUBLIC__/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
                    filebrowserFlashUploadUrl: '__PUBLIC__/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
                });



        //ajaxfileupload
        function BrowseServer(thumb, img_show) {
            var finder = new CKFinder();
            finder.selectActionFunction = function(fileUrl){

                $("#"+thumb).val(fileUrl);
                $("#"+img_show).attr("src",""+fileUrl+"");
            } //当选中图片时执行的函数
            finder.popup();//调用窗口
        }

        $(".thumb_del").click(function(){
            $("#thumb").val('');
            $("#img_show").attr("src",'');
        });





        $(".submit").click(function(){
            var title = $(".title");

            if(title.val() == '') {
                alert("标题不能为空！");
                title.focus();
                return false;
            }
//        if(CKEDITOR.instances.editor1.getData() == '') {
//            alert("内容不能为空！");
//            content.focus();
//            return false;
//        }
            var type = $("#select").find("option:selected").attr("data-type");
            if (type == 'no_add') {
                alert("您所选择的栏目是封面栏目，不能添加文章！");
                return false;
            }
        })


        function BrowseServerFile(file) {
            var finder = new CKFinder();
            finder.selectActionFunction = function(fileUrl){

                $("#"+file).val(fileUrl);
            } //当选中图片时执行的函数
            finder.popup();//调用窗口
        }

        $(".add_file").click(function(){

            var i=$('.file').size()

            var n = i+1;
            var html = '<div class="control-group file">'+
                    '<label class="col-sm-2 control-label">附件('+n+'):</label>'+
                    '<div class="controls">'+
                    '<input type="text" id="file'+n+'" class="span5" name="file[]"/>&nbsp;'+
                    "<input type='button'  value='上 传' onclick=BrowseServer('file"+n+"') class='btn btn-success' />&nbsp;"+
                    '<input type="button"  value="删 除" class="file_del btn btn-danger" />&nbsp;'+
                    '</div>'+
                    '</div>';
            console.log(html);
            if(n < 6) {
                $(".file:last").after(html);
            } else {
                alert("您最多只能添加5个附件！");
                return false;
            }
            $(this).blur();  //失去焦点
            return false;   //不跳转
        });


        //删除缩略图输入框
        $(document).on('click','.file_del',function () {
            $(this).parent().parent().remove();
        });
        $(".file_del1").click(function(){
            $("#file1").val('');
        });


    </script>
</block>

